package com.qihoo360.mobilesafe.opti.powerctl.ui.assist;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.qihoo360.mobilesafe.opti.powerctl.R;

public class SwitcherItemView extends LinearLayout implements AnimationListener {

	private Context mContext;
	private ImageView mSwitchIcon;
	private TextView mSwitchLable;

	private Animation mInAnimation;
	private Animation mOutAnimation;

	private int g = -1;

	public SwitcherItemView(Context context, AttributeSet attrs) {
		super(context, attrs);
		mContext = context;
		View view = inflate(mContext, R.layout.switcher_item, null);
		setDuplicateParentStateEnabled(false);
		setOrientation(VERTICAL);
		setGravity(Gravity.CENTER);
		setClickable(true);
		TypedArray mTypedArray = mContext.obtainStyledAttributes(attrs,
				Las.switcher);
		String str_index = mTypedArray.getString(1);
		mSwitchIcon = (ImageView) findViewById(R.id.switch_icon);
		mSwitchLable = (TextView) findViewById(R.id.switch_label);
		mSwitchLable.setText(str_index);
		int resId = mTypedArray.getResourceId(0, g);
		mSwitchIcon.setImageResource(resId);
		mTypedArray.recycle();
		WindowManager wm = (WindowManager) context.getSystemService("window");
		Display display = wm.getDefaultDisplay();
		DisplayMetrics displayMetrics = new DisplayMetrics();
		display.getMetrics(displayMetrics);
		int densityDpi = displayMetrics.densityDpi;
		switch (densityDpi) {
		case 240:
			mSwitchLable.setTextSize(16720);
			break;
		case 320:
			mSwitchLable.setTextSize(16752);
			break;
		}
	}

	public void a(int a, int b, int c) {
		clearAnimation();
		startAnimation(mInAnimation);
	}

	public void setStatus(int resId, int textSrc, int textColor) {
		if (resId == -1 && textSrc == -1 && textColor == -1)
			return;
		mSwitchIcon.setImageResource(resId);
		mSwitchLable.setText(textSrc);
		mSwitchLable.setTextColor(textColor);
	}

	@Override
	public void onAnimationEnd(Animation animation) {

	}

	@Override
	public void onAnimationRepeat(Animation animation) {

	}

	@Override
	public void onAnimationStart(Animation animation) {

	}

}
